/**         .----.
 *       _.'__    `.
 *   .--($)($$)---/#\
 * .' @          /###\
 * :         ,   #####
 *  `-..__.-' _.-\###/
 *        `;_:    `"'
 *      .'"""""`.
 *     /,     ,\\
 *    //  !BUG  \\
 *    `-._______.-'
 *    ___`. | .'___
 *   (______|______)
 *
 * 邮件自动补全-JS
 * @author kwun
 * @email 527565073@qq.com
 */

+(function ( $, window, document, undefined ) {

    var pluginName = "tabnav",
        defaults = {
            effect: 'scale'
        };

    function Plugin( element, options ) {
        this.element = element;
        this.$elem = $(this.element);
        this.options = $.extend( {}, defaults, options );
        this._defaults = defaults;
        this._name = pluginName;
        this.init();
    }

    Plugin.prototype = {

        init: function() {

            var links = this.$elem.find('a');
            var firstchild = this.$elem.find('li:first-child').find('a');
            var lastchild = this.$elem.find('li:last-child').after('<span class="tabnavclear"></span>');

            switch(this.options.effect){
                case 'scale':
                    tab_content = this.$elem.find('div').not(':first').not(':nth-child(1)').addClass('hidescale');
                    break;
                case 'slideLeft':
                    tab_content = this.$elem.find('div').not(':first').not(':nth-child(1)').addClass('hideleft');
                    break;
                case 'scaleUp':
                    tab_content = this.$elem.find('div').not(':first').not(':nth-child(1)').addClass('hidescaleup');
                    break;
                case 'flip':
                    tab_content = this.$elem.find('div').not(':first').not(':nth-child(1)').addClass('hideflip');
                    break;
                default:

            }


            var firstdiv = this.$elem.find('#tabs_container');
            var firstdivheight = firstdiv.find('div:first').height();
            var alldivs = this.$elem.find('div:first').find('div');

            alldivs.css({'position': 'absolute','top':'40px'});
            firstdiv.css('height',firstdivheight+'px');
            firstchild.addClass('tabulous_active');

            links.bind('click', {myOptions: this.options}, function(e) {
                e.preventDefault();
                var $options = e.data.myOptions;
                var effect = $options.effect;
                var mythis = $(this);
                var thisform = mythis.parent().parent().parent();
                var thislink = mythis.attr('href');

                firstdiv.addClass('transition');
                links.removeClass('tabnav_active');
                mythis.addClass('tabnav_active');
                thisdivwidth = thisform.find('div'+thislink).height();

                switch(effect){
                    case 'scale':
                        alldivs.removeClass('showscale').addClass('make_transist').addClass('hidescale');
                        thisform.find('div'+thislink).addClass('make_transist').addClass('showscale');
                        break;
                    case 'slideLeft':
                        alldivs.removeClass('showleft').addClass('make_transist').addClass('hideleft');
                        thisform.find('div'+thislink).addClass('make_transist').addClass('showleft');
                        break;
                    case 'scaleUp':
                        alldivs.removeClass('showscaleup').addClass('make_transist').addClass('hidescaleup');
                        thisform.find('div'+thislink).addClass('make_transist').addClass('showscaleup');
                        break;
                    case 'flip':
                        alldivs.removeClass('showflip').addClass('make_transist').addClass('hideflip');
                        thisform.find('div'+thislink).addClass('make_transist').addClass('showflip');
                        break;
                    default:

                }
                firstdiv.css('height',thisdivwidth+'px');
            });
        },
        yourOtherFunction: function(el, options) {
            // some logic
        }
    };

    $.fn[pluginName] = function ( options ) {
        return this.each(function () {
            new Plugin( this, options );
        });
    };

})( jQuery, window, document );

